#!/usr/bin/env python
PACKAGE = "ipa_room_segmentation"

from dynamic_reconfigure.parameter_generator_catkin import *

gen = ParameterGenerator()

method_enum = gen.enum([ gen.const("MorphologicalSegmentation", int_t, 1, "Use the morphological segmentation algorithm."),
                       gen.const("DistanceSegmentation", int_t, 2, "Use the distance segmentation algorithm."),
                       gen.const("VoronoiSegmentation", int_t, 3, "Use the Voronoi segmentation algorithm."),
                       gen.const("SemanticSegmentation", int_t, 4, "Use the semantic/feature-based segmentation algorithm."),
                       gen.const("RandomFieldSegmentation", int_t, 5, "Use the voronoi-random-field segmentation algorithm."),
                       gen.const("PassThroughSegmentation", int_t, 99, "Use the pass through segmentation algorithm.")],
                     "Segmentation algorithm")
gen.add("room_segmentation_algorithm", int_t, 0, "Segmentation method", 3, 1, 99, edit_method=method_enum)

gen.add("display_segmented_map", bool_t, 0, "Show the resulting segmented map directly", False)
gen.add("publish_segmented_map", bool_t, 0, "Publish the resulting segmented map as grid map", False)

# room area factor-> Set the limitation of area of the room -------> in [m^2]
#morphological segmentation: 47.0 - 0.8 (means the room area after eroding/shrinking s.t. too small/big contours are not treated as rooms)
gen.add("room_area_factor_upper_limit_morphological", double_t, 0, "Upper room limit for morphological segmentation", 47.0, 0.0)
gen.add("room_area_factor_lower_limit_morphological", double_t, 0, "Lower room limit for morphological segmentation", 0.8, 0.0)

# distance segmentation: 163.0 - 0.35 (means the room area after decreasing the boundary for the binary filter s.t. too small/big contours are not treated as rooms)
gen.add("room_area_factor_upper_limit_distance", double_t, 0, "Upper room limit for distance segmentation", 163.0, 0.0)
gen.add("room_area_factor_lower_limit_distance", double_t, 0, "Lower room limit for distance segmentation", 0.35, 0.0)

# Voronoi segmentation: 120.0 - 1.53 (means the max/min area that an area separated by critical lines is allowed to have)
gen.add("room_area_factor_upper_limit_voronoi", double_t, 0, "Upper room limit for Voronoi segmentation", 1000000.0, 0.0)
gen.add("room_area_factor_lower_limit_voronoi", double_t, 0, "Lower room limit for Voronoi segmentation", 0.1, 0.0)

# Semantic Segmentation: 23.0 - 1.0 (means the max/min area a connected classified region is allowed to have)
gen.add("room_area_factor_upper_limit_semantic", double_t, 0, "Upper room limit for semantic/feature-based segmentation", 1000000.0, 0.0) # if you choose this value small (i.e 23.0) then too big hallway contours are randomly separated into smaller regions using a watershed algorithm, which can look bad
gen.add("room_area_factor_lower_limit_semantic", double_t, 0, "Lower room limit for semantic/feature-based segmentation", 1.0, 0.0)

# Voronoi random field segmentation: 1000000.0 - 1.53 (means the max/min area a connected classified region is allowed to have)
gen.add("room_area_upper_limit_voronoi_random", double_t, 0, "Upper room limit for Voronoi-random-field segmentation", 1000000.0, 0.0)
gen.add("room_area_lower_limit_voronoi_random", double_t, 0, "Lower room limit for Voronoi-random-field segmentation", 1.53, 0.0)

# Passthrough segmentation: 1000000.0 - 1.53 (means the max/min area a connected classified region is allowed to have)
gen.add("room_area_upper_limit_passthrough", double_t, 0, "Upper room limit for Voronoi-random-field segmentation", 1000000.0, 0.0)
gen.add("room_area_lower_limit_passthrough", double_t, 0, "Lower room limit for Voronoi-random-field segmentation", 1.0, 0.0)

# parameters for the voronoi segmentation that specify the neighborhood for critical Point extraction and the distance between critical Points. 
gen.add("voronoi_neighborhood_index", int_t, 0, "Size of neighborhood on graph for Voronoi segmentation, larger value sets a larger neighborhood for searching critical points", 280, 0)
gen.add("max_iterations", int_t, 0, "Max number of Iterations for search of neighbors, also used for the vrf segmentation", 150, 0)
gen.add("min_critical_point_distance_factor", double_t, 0, "Minimal distance factor between two critical points before one of it gets eliminated", 0.5, 0.0)
gen.add("max_area_for_merging", double_t, 0, "Maximal area [m^2] of a room that should be merged with its surrounding rooms, also used for the voronoi random field segmentation", 12.5, 0.0)

# parameters for the voronoi random field segmentation that specify the size of the neighborhood generated on the Voronoi graph, the minimal
# size this neighborhood can have, how far base nodes for each node on the graph need to be apart and how many iterations the inference 
# max. should do
gen.add("voronoi_random_field_epsilon_for_neighborhood", int_t, 0, "Larger value sets larger neighborhood, concentrated in a node of the conditional random field", 5, 0)
gen.add("min_neighborhood_size", int_t, 0, "Min. size of the above mentioned neighborhood", 4, 0)
gen.add("min_voronoi_random_field_node_distance", double_t, 0, "Min distance the base nodes for each crf node need to be apart", 7.0, 0.0)
gen.add("max_voronoi_random_field_inference_iterations", int_t, 0, "Max number of iterations the inference algorithm should do", 9000, 0)

exit(gen.generate(PACKAGE, "room_segmentation_server", "RoomSegmentation"))